#pragma once
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <queue>

using namespace std;

class outmgr
{
public:
    int interval_threshold = 100;
    int interval_count = interval_threshold + 1; // 保证0时刻数据可以记录下来
    std::queue<vector<double>> data;
    vector<double> sdata;
    fstream fout;
    string outdir = "./output.csv";
    string str_title = "";
    bool title_printed = false;
    vector<string> titles;
    outmgr()
    {
        fout.open(outdir, ios::out);
        if (!fout)
        {
            perror("output.csv open failed.\n");
            exit(-1);
        }
    }
    ~outmgr()
    {
        fout.close();
    }
    void add(double data, string label)
    {
        sdata.push_back(data);
        if(find(titles.begin(),titles.end(),label) == titles.end())
        {
            titles.push_back(label);
        }
    }
    void integrate()
    {
        data.push(sdata);
        sdata.clear();
    }
};